﻿#parse("/layout/header.htm")
<script>
    var tupianlink1 = "$!ad0.url";
    var tupianlink2 = "$!ad1.url";
    var tupianlink3 = "$!ad2.url";

    $(function(){
        $("input[type='file']").unbind("change");
        $("input[type='file']").bind("change", uploadfile);
    });
   
    function uploadfile(event) {       
        var index = $(event.target).attr("v");
        var img_file = event.target.files[0];
        if (!img_file) return false;

        if (!(/^image\/.*$/.test(img_file.type))) {
            alert('请选择图片文件');
            return false;
        }
        fReader = new FileReader();
        fReader.readAsDataURL(img_file);
        fReader.onload = function (e) {            
            $.post("/upload", { img: e.target.result }, function (ret) {
                if (ret[0] == '/') {
                    if(index==1)tupianlink1 = ret;
                    if(index==2)tupianlink2 = ret;
                    if(index==3)tupianlink3 = ret;
                    $("#imgad"+index).attr("src", ret);
                } else {
                }

            });
        };
    }
</script>
<title>更换广告</title>
<div data-role="page" id="page">
    <div data-role="content">
        
        <p>广告1（建议图片大小是:640*120)<br/>
        <img src="$!ad0.url" style="width: 100%;" id="imgad1" />
            <input type="file" v="1"/>
        <input type="text" style="width: 100%;" id="txtad1" placeholder="链接到您的推广网址,例如：a.com或http://a.com等" value="$!ad0.link" />
        
        </p>

        
        <p>广告2$funhelper.encode($yonghu.style,"1","（建议图片大小是:640*120)","2","（建议图片大小是:640*120)","（<a href='/vip'>普通vip用户才能更换</a>)")<br/>
        <img src="$!ad1.url" style="width: 100%;" id="imgad2" />
            #if($yonghu.style > 0)
            <input type="file" v="2"/>
         #end
        <input type="text" $funhelper.encode($yonghu.style,"1","","2","","disabled") style="width: 100%;" id="txtad2" placeholder="链接到您的推广网址,例如：a.com或http://a.com等" value="$!ad1.link" />
         
        </p>

        <p>广告3$funhelper.encode($yonghu.style,"2","（建议图片大小是:640*120)","（<a href='/vip'>高级vip用户才能更换</a>)")<br/>
        <img src="$!ad2.url" style="width: 100%;" id="imgad3"/>
            #if($yonghu.style > 1)
            <input type="file" v="3"/>
         #end
        <input type="text" $funhelper.encode($yonghu.style,"2","","disabled") style="width: 100%;" id="txtad3" placeholder="链接到您的推广网址,例如：a.com或http://a.com等" value="$!ad2.link"  />
        
        </p>

        <p>如果广告图片尺寸不合适，我们会直接裁切图像中间部分。</p>
        #if($yonghu.style == 0)
        <p>免费用户只允许更换一条广告,普通VIP能更换两条广告,高级VIP能更换三条广告。<a href="javascript:location.href='vip';">点击成为VIP</a></p>
        #end
        
        <a data-role="button" href="#" id="savead" data-theme="c">保存</a>
        <a data-role="button" href="javascript:location.href='/hello'">返回广告加介绍</a>
    </div>
</div>
#parse("/layout/footer.htm")

<script>

    $('#savead').on('click', function () {
        #if($yonghu.style == 0)
            if (tupianlink1 == "") {
                alert("未上传广告1的图片");
                return false;
            }
        #end

        #if($yonghu.style > 0)
            if (tupianlink1 == "" && tupianlink2 == ""  && tupianlink3 == "" ) {
                alert("至少要上传一条广告");
                return false;
            }
        #end

        var txt1 = $("#txtad1").val();
        var txt2 = $("#txtad2").val();
        var txt3 = $("#txtad3").val();

        $.post("setsave",{t1:tupianlink1,l1:txt1,t2:tupianlink2,l2:txt2,t3:tupianlink3,l3:txt3},function (ret) {
           
            alert('广告设置成功!'); 
            
        });
    });

</script>






